﻿@model BackEnd.Models.MenuModel
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>List ContentType</h2>    
    <a class="bt_green" href="/Menu/Create"><span class="bt_green_lft"></span><strong>Create</strong><span class="bt_green_r"></span></a>
    <a class="bt_red" href="#" onclick="DeleteSelectedItems(this);"><span class="bt_red_lft"></span><strong>Delete items</strong><span class="bt_red_r"></span></a>
<table id="rounded-corner"><thead>
    <tr>
        <th class="rounded-company" scope="col"><input id="chkAll" onclick="javascript:SelectAll(this);" type="checkbox" /></th>
        <th class="rounded" scope="col">Id</th>
        <th class="rounded" scope="col">Menu Name</th>
        <th class="rounded" scope="col">Redirect Url</th>
        <th class="rounded" scope="col">Order</th>
        <th class="rounded" scope="col">Status</th>
        <th class="rounded-q4" scope="col"></th>
    </tr>
    @foreach (var item in Model.ListMenu)
    { 
        <tr>
            <td>
                @Html.CheckBox("check", new { itemid = item.Id, refer = "chk", onclick = "javascript:SelectOne(this)" })
            </td>
            <td>@item.Id</td>
            <td>@item.MenuName</td>
            <td>@item.RedirectUrl</td>
            <td>@item.Order</td>
            <td>@item.Status</td>
            <td>                
                <a href="/Menu/Edit?id=@item.Id"><img src="/Content/Images/user_edit.png" /></a>
            </td>
        </tr>
    }</thead>
</table>
<input id="hidMenuId" type="hidden" />
    <script type="text/javascript">
        /*Check, Check All*/
        function SelectAll(spanChk) {

            var hidSelected = $("input[id='hidMenuId']");
            var chkList = $("input[refer='chk']");
            var str = "";

            for (var i = 0; i < chkList.length; i++) {
                var chk = chkList[i];
                chk.checked = spanChk.checked;
                if (chk.checked) {
                    str = str + $(chk).attr("itemid") + "_";
                }
            }
            str = str == "" ? "" : str.substring(0, str.length - 1);
            hidSelected.attr("value", str);
            //alert(hidSelected.val());
        }
        function SelectOne() {
            var hidSelected = $("input[id='hidMenuId']");
            var chkList = $("input[refer='chk']");
            var str = "";

            for (var i = 0; i < chkList.length; i++) {
                var chk = chkList[i];
                if (chk.checked) {
                    str = str + $(chk).attr("itemid") + "_";
                }
            }
            str = str == "" ? "" : str.substring(0, str.length - 1);
            hidSelected.attr("value", str);
        }
        function DeleteSelectedItems() {

            if (confirm('Are you sure that want delete these items?')) {
                var hidSelected = $("input[id='hidMenuId']");
                if (hidSelected.val() != "") {

                    var rows = $("input:checked");
                    rows.each(function () {
                        $(this).parent().parent().remove();
                    });

                    $.ajax({
                        url: '/Menu/Delete',
                        type: 'POST',
                        data: {
                            listId: hidSelected.val()
                        },
                        success: function (data) {
                            
                        }
                    });

                }
            }
        }
    </script>

